r09228001 地理所碩一 楊宇翔
2021/3/12 (Fri.)
提供實習資料
media_nodes.csv
media_edges.csv
The 1st graph
node size by [audience.size] edge width by [weight]
library(igraph)
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
setwd("~/Downloads/Lab1")
#data input 2 有方向性的網絡
data2 <- "media_edges.csv" #線資料
edges <- read.table(data2, header=T, sep=",")
data3<- "media_nodes.csv" #點資料
nodes <- read.table(data3, header=T, sep=",")
net=graph.data.frame (edges, directed=TRUE,nodes) # directed=True 有方向性
colrs <- c("grey", "red", "yellow")
V(net)$color <- colrs[V(net)$media.type]
# Set node size based on audience size:
V(net)$size <- V(net)$audience.size*0.7
# The labels are currently node IDs.
# Setting them to NA will render no labels:
V(net)$label.color <- "black"
V(net)$label <- NA
# Set edge width based on weight:
E(net)$width <- E(net)$weight/6
#change arrow size and edge color:
E(net)$arrow.size <- .2
E(net)$edge.color <- "gray80"
E(net)$width <- 1+E(net)$weight/12
plot(net, main="networks of media, category and audience size")
?plot
## Help on topic 'plot' was found in the following packages:
##
## Package Library
## graphics /Library/Frameworks/R.framework/Versions/4.0/Resources/library
## base /Library/Frameworks/R.framework/Resources/library
##
##
## Using the first match ...
legend(x=-1.5, y=-1.1, c("Newspaper","Television", "Online News"), pch=21,
col="#777777", pt.bg=colrs, pt.cex=2, cex=.8, bty="n", ncol=1)
The 2nd graph
node label by [media] edge width by [weight]
plot(net, vertex.shape="none", vertex.label=V(net)$media,
vertex.label.font=2, vertex.label.color="black",
vertex.label.cex=0.9, edge.color="grey", main="networks of names of media")
The 3rd and 4th graphs
node size by [audience.size] edge width by [weight]
net.m <- net - E(net)[E(net)$type=="hyperlink"] #another way to delete edges
net.h <- net - E(net)[E(net)$type=="mention"]
# Plot the two links separately:
par(mfrow=c(1,2))
# Make sure the nodes stay in place in both plots:
l <- layout_with_fr(net)
plot(net.h, vertex.color="orange", layout=l, main="network of media.Tie: Hyperlink")
plot(net.m, vertex.color="blue", layout=l, main="network of media.Tie: Mention")
原始資料
edges
## from to weight type
## 1 s01 s02 10 hyperlink
## 2 s01 s02 12 hyperlink
## 3 s01 s03 22 hyperlink
## 4 s01 s04 21 hyperlink
## 5 s04 s11 22 mention
## 6 s05 s15 21 mention
## 7 s06 s17 21 mention
## 8 s08 s09 11 mention
## 9 s08 s09 12 mention
## 10 s03 s04 22 hyperlink
## 11 s04 s03 23 hyperlink
## 12 s01 s15 20 mention
## 13 s15 s01 11 hyperlink
## 14 s15 s01 11 hyperlink
## 15 s16 s17 21 mention
## 16 s16 s06 23 hyperlink
## 17 s06 s16 21 hyperlink
## 18 s09 s10 21 mention
## 19 s08 s07 21 mention
## 20 s07 s08 22 mention
## 21 s07 s10 21 hyperlink
## 22 s05 s02 21 hyperlink
## 23 s02 s03 21 hyperlink
## 24 s02 s01 23 hyperlink
## 25 s03 s01 21 hyperlink
## 26 s12 s13 22 hyperlink
## 27 s12 s14 22 mention
## 28 s14 s13 21 mention
## 29 s13 s12 21 hyperlink
## 30 s05 s09 2 hyperlink
## 31 s02 s10 5 hyperlink
## 32 s03 s12 1 hyperlink
## 33 s04 s06 1 mention
## 34 s10 s03 2 hyperlink
## 35 s03 s10 2 mention
## 36 s04 s12 3 hyperlink
## 37 s13 s17 1 mention
## 38 s06 s06 1 hyperlink
## 39 s14 s11 1 mention
## 40 s03 s11 1 hyperlink
## 41 s12 s06 2 mention
## 42 s04 s17 2 mention
## 43 s17 s04 4 hyperlink
## 44 s08 s03 2 hyperlink
## 45 s03 s08 4 hyperlink
## 46 s07 s14 4 mention
## 47 s15 s06 4 hyperlink
## 48 s15 s04 1 hyperlink
## 49 s05 s01 1 mention
## 50 s02 s09 1 hyperlink
## 51 s03 s05 1 hyperlink
## 52 s07 s03 1 mention
nodes
## id media media.type type.label audience.size
## 1 s01 NY Times 1 Newspaper 20
## 2 s02 Washington Post 1 Newspaper 25
## 3 s03 Wall Street Journal 1 Newspaper 30
## 4 s04 USA Today 1 Newspaper 32
## 5 s05 LA Times 1 Newspaper 20
## 6 s06 New York Post 1 Newspaper 50
## 7 s07 CNN 2 TV 56
## 8 s08 MSNBC 2 TV 34
## 9 s09 FOX News 2 TV 60
## 10 s10 ABC 2 TV 23
## 11 s11 BBC 2 TV 34
## 12 s12 Yahoo News 3 Online 33
## 13 s13 Google News 3 Online 23
## 14 s14 Reuters.com 3 Online 12
## 15 s15 NYTimes.com 3 Online 24
## 16 s16 WashingtonPost.com 3 Online 28
## 17 s17 AOL.com 3 Online 33